//
//  Lahelper.m
//  51易借
//
//  Created by apple on 2017/9/15.
//  Copyright © 2017年 张睿. All rights reserved.
//

#import "Lahelper.h"

@implementation Lahelper
+ (NSDate *)dateWithTimeIntervalInMilliSecondSince1970:(double)timeIntervalInMilliSecond {
    NSDate *ret = nil;
    if(timeIntervalInMilliSecond>0){
        double timeInterval = timeIntervalInMilliSecond;
        // judge if the argument is in secconds(for former data structure).
        if(timeIntervalInMilliSecond > 140000000000) {
            timeInterval = timeIntervalInMilliSecond / 1000;
        }
        ret = [NSDate dateWithTimeIntervalSince1970:timeInterval];
    }
    
    return ret;
}


+ (NSDate *)dateWithTimeIntervalInMilliSecondSince1970:(double)timeIntervalInMilliSecond WithFormatted:(NSString*)formatted{
    NSDate *ret = nil;
    double timeInterval = timeIntervalInMilliSecond;
    // judge if the argument is in secconds(for former data structure).
    if(timeIntervalInMilliSecond > 140000000000) {
        timeInterval = timeIntervalInMilliSecond / 1000;
    }
    ret = [NSDate dateWithTimeIntervalSince1970:timeInterval];
    
    return ret;
}


+ (NSString *)formattedTimeFromTimeInterval:(long long)time{
    return [self formattedTime:[self dateWithTimeIntervalInMilliSecondSince1970:time]];
}


+ (NSString *)formattedTimeFromTimeInterval:(long long)time formatted:(NSString*)formatted{
    return [self formattedTime:[self dateWithTimeIntervalInMilliSecondSince1970:time] WithFormatted:formatted];
}



/*标准时间日期描述*/
+(NSString *)formattedTime:(NSDate*)date WithFormatted:(NSString*)formatted{
    
    if(date){
        
        
        NSDateFormatter* formatter = [[NSDateFormatter alloc]init];
        [formatter setDateFormat:formatted.length?formatted:@"YYYY-MM-dd"];
        NSString * dateNow = [formatter stringFromDate:date];
        return dateNow;
    }
    else
    {
        return @"----";
    }
}




/*标准时间日期描述*/
+(NSString *)formattedTime:(NSDate*)date{
    
    
    if(date){
        NSDateFormatter* formatter = [[NSDateFormatter alloc]init];
        [formatter setDateFormat:@"YYYY-MM-dd"];
        NSString * dateNow = [formatter stringFromDate:date];
        return dateNow;
    }else
    {
        return @"----";
    }
}


@end
